package com.online.college.rest.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.online.college.common.web.JsonView;
import com.online.college.rest.business.IClassifyService;
import com.online.college.rest.dto.ClassifyDto;

@Controller
public class PortalClassifyController {

	@Autowired
	private IClassifyService classifyService;

	@RequestMapping(value = "getClassifyJson")
	@ResponseBody
	public String getClassifyJson(HttpServletRequest request) {
		Map<String,ClassifyDto> map = new HashMap<String,ClassifyDto>();
		List<ClassifyDto> list = new ArrayList<ClassifyDto>();
		try {
			map = classifyService.getClassifyList();
			for(Map.Entry<String, ClassifyDto> entry :map.entrySet()){
				list.add(entry.getValue());
			}
		} catch (Exception e) {
			return JsonView.render(1);
		}
		return request.getParameter("callback")+"("+JsonView.render(list)+")";
	}
}
